package com.validator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
 * 检验器构造类
 * @author : zmj
 * @description :
 * ---------------------------------
 */
public class ValidatorBuilder {
    private List<Validator> validators;

    public ValidatorBuilder addValidator(Validator... validator){
        Optional<List<Validator>> vcp = Optional.ofNullable( validators);
        validators = vcp.orElse(new ArrayList<>());
        Collections.addAll(validators, validator);
        return this;
    }

    public ValidatorChain build(){
        try {
            return new ValidatorChain(validators);
        }finally {
            validators=null;
        }
    }

}
